package com.k.base.jdk.stream.map;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MapTest {
    public static void main(String[] args) {

    }
    private  void test(){
        List<User> data = getData();
        // 根据 type 分组
        Map<String,List<User>> map = groupBy(data);

        // 修改 map key
        Map<String,List<User>> newMap = null;
//                map.entrySet()
//                .stream()
//                .collect(Collectors.toMap(e -> modifyKey(e.getKey()), Map.Entry::getValue));
//        System.out.println(newMap);
    }

    private  Object modifyKey(String key) {
        if("3".equals(key)){
            return "3gai";
        }
        return null;
    }

    /**
     * 根据 type 分组
     * @param list
     * @return
     */
    private  Map<String,List<User>> groupBy(List<User> list){
        return list.stream().collect(Collectors.groupingBy(User::getType));
    }

    private  List<User> getData(){
        List<User> list = new ArrayList<>();
        for(int i=0;i<10;i++){
            User u = new User();
            u.setGud(i+"");
            u.setName("xiao"+i);
            u.setType("3");
            list.add(u);
        }
        return list;
    }


}
